package com.htandroid.htandroid.webservice;

import android.util.Xml;

import com.htandroid.htandroid.entity.RdrecordsAppList_detail;
import com.htandroid.htandroid.entity.UffjqgdList_detail;

import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class abXMLKcappdetail {

    /**
     * 解析评论xml信息
     *
     * @param content
     * @return
     */
    public static ArrayList<RdrecordsAppList_detail> paraseCommentInfors(String content) {
        List<String> list = new ArrayList<String>();
        content = content.replace("RdrecordsAppList_detail=anyType", "#=#");
        String[] strs = content.split("#=");
        for (int i = 0; i < strs.length; i++) {
            if (strs[i].contains("#")) {
                list.add(strs[i].replace("#", "").trim().replace(" ", ""));
            }
        }
        ArrayList<RdrecordsAppList_detail> rdapplist_detail = new ArrayList<RdrecordsAppList_detail>();
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                list.set(i, list.get(i).replace(";};};}", "\"}"));
            }
            list.set(i, list.get(i).replace(";};", "\"}").replace("=", "\":\"").replace(";", "\",\"").replace("{ID", "{\"ID"));
            try {
                RdrecordsAppList_detail info = new RdrecordsAppList_detail();
                JSONObject dataJson = new JSONObject(list.get(i));
                info.setID(string2null(dataJson.getString("ID")));
                info.setCvouchid(string2null(dataJson.getString("cvouchid")));
                info.setCwhcode(string2null(dataJson.getString("cwhcode")));
                info.setCwhname(string2null(dataJson.getString("cwhname")));
                info.setCdepcode(string2null(dataJson.getString("cdepcode")));
                info.setCdepname(string2null(dataJson.getString("cdepname")));
                info.setCinvcode(string2null(dataJson.getString("cinvcode")));
                info.setInum(string2null(dataJson.getString("inum")));
                info.setIsnum(string2null(dataJson.getString("isnum")));
                info.setIsquantity(string2null(dataJson.getString("isquantity")));
                info.setCdefine22(string2null(dataJson.getString("cdefine22")));
                info.setCdefine23(string2null(dataJson.getString("cdefine23")));
                info.setCdefine24(string2null(dataJson.getString("cdefine24")));
                info.setCdefine25(string2null(dataJson.getString("cdefine25")));
                info.setCinvname(string2null(dataJson.getString("cinvname")));
                info.setCinvstd(string2null(dataJson.getString("cinvstd")));
                info.setCinvm_unit(string2null(dataJson.getString("cinvm_unit")));
                info.setCinva_unit(string2null(dataJson.getString("cinva_unit")));
                info.setIinvexchrate(string2null(dataJson.getString("iinvexchrate")));
                info.setBinvquality(string2null(dataJson.getString("binvquality")));
                info.setCdisapprovereason(string2null(dataJson.getString("cdisapprovereason")));
                info.setBapprove(string2null(dataJson.getString("bapprove")));
                info.setRds_appid(string2null(dataJson.getString("rds_appid")));
                info.setInorder(string2null(dataJson.getString("inorder")));
                info.setCtype(string2null(dataJson.getString("ctype")));
                info.setIquantity(string2null(dataJson.getString("iquantity")));
                info.setIprice(string2null(dataJson.getString("iprice")));
                info.setIamount(string2null(dataJson.getString("iamount")));
                info.setCdefine26(string2null(dataJson.getString("cdefine26")));
                info.setCdefine27(string2null(dataJson.getString("cdefine27")));
                info.setNotaxprice(string2null(dataJson.getString("notaxprice")));
                info.setTaxrate(string2null(dataJson.getString("taxrate")));
                info.setTax(string2null(dataJson.getString("tax")));
                info.setNotaxamount(string2null(dataJson.getString("notaxamount")));
                info.setCchecker(string2null(dataJson.getString("cchecker")));
                info.setCcheckdate(string2null(dataJson.getString("ccheckdate")));
                info.setCdefine4(string2null(dataJson.getString("cdefine4")));
                info.setSuccount(string2null(dataJson.getString("succount")));
                info.setBclose(string2null(dataJson.getString("bclose")));
                info.setDclose_date(string2null(dataJson.getString("dclose_date")));
                rdapplist_detail.add(info);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return rdapplist_detail;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }
}
